// pages/mine/attention/attention.js
const tools = require('../../../utils/tool')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    attention: 0,
    followList: [], //关注列表
    next_page_url: '', //下一页路径
    page: 0, //当前页数
    user_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.user_id!='me'){
      this.setData({
        user_id:options.user_id
      })
    }
    this.setData({
      attention: options.attention,
      isMy:options.isMy
    })
    if (options.attention == 1) {
      this.getGuzhu('/api/applets/follow/lists') //关注列表
    } else {
      this.getGuzhu('/api/applets/follow/fans') //粉丝列表
    }

  },
  getGuzhu(url) {
    tools.showLoading()
    if(this.data.user_id==''){
      var params={}
    }else{
      var params={
        user_id:this.data.user_id
      }
    }
    let guzhu = tools.request(url, 'get', params, wx.getStorageSync('token'))
    guzhu.then(res => {
      console.log(res)
        wx.hideLoading()
        if (res.data.status) {
          let followList = this.data.followList.concat(res.data.list.data)
          // followList.map(item=>{
          //   item.
          // })
          this.setData({
            followList,
            next_page_url: res.data.list.next_page_url,
            total: res.data.list.total
          })
        } else {
          tools.showToast(res.data.error_msg, 'error')
        }
      })
      .catch(err => {
        tools.showToast(err.errMsg, 'error')
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let total = this.data.total
    let followList = this.data.followList.length
    let next_page_url = this.data.next_page_url
    if (next_page_url!=null) {
      next_page_url=next_page_url = '/' + next_page_url.split('/').slice(3).join('/');
      this.getGuzhu(next_page_url)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 跳转到主页
})